{__NOLAYOUT__}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/agent/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/view_order.css"/>
    <script type="text/javascript" src="/agent/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/agent/js/iScroll.js" ></script>
    <script type="text/javascript" src="/agent/js/Mdate/Mdate.js" ></script>
    <link rel="stylesheet" href="/agent/css/Mdate.css" />
    <script type="text/javascript" src="/agent/js/rem.js" ></script>
    <script type="text/javascript" src="/agent/js/mescroll.min.js" ></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/mescroll.min.css"/>
    <title>查看账单</title>
</head>
<body>
<div class="top" style="height: 4rem;">
    <img src="{$agent.picture}"/>
    <p class="bookstore">{$agent.agent_name}</p>
</div>
<div class="blank" style="height: 1.2rem;width: 100%;background: #fff;position: fixed;top: 4rem;left: 0;">
    <div class="money">
        <div class="money_left">
            <p>保证金金额</p>
            <p style="color: #f3494c;font-size: 0.35rem;">¥ {$agent.bond_amount}</p>
        </div>
        <div class="money_right">
            <p>可抵扣金额</p>
            <p style="font-size: 0.35rem;">¥ {$agent.deduction_amount}</p>
        </div>
    </div>
</div>
<div class="date">
    <div id="dateShowBtn">
        <span></span>
        <input disabled type="text" id="dateSelectorOne" value=""  data-year="" data-month="">
        <img src="/agent/img/xia.png"/>
    </div>
    {if $auth->check('agent/info/mobileexport')} <div class="leading-out">导出</div> {/if}
    <p>
        支出￥<span class="zhichu">0.00</span>
        收入￥<span class="shouru">0.00</span>
    </p>
</div>
<div id="mescroll" class="mescroll bill_mescroll">
    <ul class="forlist" >
    </ul>
</div>
{if $auth->check('agent/info/mobileupmargin') || $auth->check('agent/info/mobileaddmargin')}
<div class="footer">
    <ul>
        {if $auth->check('agent/info/mobileaddmargin')}
            <li class="add_deposit">添加保证金</li>
        {/if}
        {if $auth->check('agent/info/mobileupmargin')}
            <li class="add_deduct">抵扣费用调整</li>
        {/if}
    </ul>
</div>
{/if}
<div class="deposit_mask">
    <div class="deposit">
        <img class="deposit_close" src="/agent/img/cha.png"/>
        <h2>保证金添加</h2>
        <div style="margin-top: 0.5rem;">
            <span>金额</span>
            <div class="box">
                <div>
                    <input class="cut" type="button" value="-" onclick="goods_cut();">
                </div>
                <div>
                    <input class="num" type="number" id="sku_number" name="number" value="1">
                </div>
                <div>
                    <input class="add" type="button" value="+" onclick="goods_add();">
                </div>
            </div>
        </div>
        <div style="margin-top: 0.5rem;">
            <span>备注</span>
            <textarea id="content"></textarea>
        </div>
        <div class="submit_deposit">确定</div>
    </div>
</div>
<div class="deduct_mask">
    <div class="deduct">
        <img class="deduct_close" src="/agent/img/cha.png"/>
        <h2>抵扣费用调整</h2>
        <div style="margin-top: 0.7rem;">
            <p>
                <span>保证金金额</span>
                <span class="baozheng"></span>
            </p>
            <p style="margin-top: 0.5rem;">
                <span>需调整金额</span>
                <input class="adjust" type="text" name="" id="" value="1000" />
            </p>
        </div>
        <div class="submit_deduct">确定</div>
    </div>
</div>
</body>

<script>
  $(function () {
    var offset = 0; //页码
    var limit = 10;  //每页数据固定条数
    var agentid = {$agent.id};
    var myDate = new Date();
    var year=myDate.getFullYear();//获取当前年
    var month= Appendzero(myDate.getMonth()+1);//获取当前月
    $('#dateShowBtn span').text(year+'年'+month+'月');
    $('#dateSelectorOne').attr('data-year',year);
    $('#dateSelectorOne').attr('data-month',month);
    $('#dateShowBtn').click(function(){
      $('#dateShowBtn span').hide();
    });
    $('.leading-out').click(function(){
      $.ajax({
        type:'post',
        dataType:'json',
        data:{date:year+month},
        url:'/admin/agent/info/mobileexport/agentid/'+agentid,
        success:function (data) {
          alert(data.msg);
        }
      });
    });
    new Mdate("dateShowBtn", {
      //"dateShowBtn"为你点击触发Mdate的id，必填项
      acceptId: "dateSelectorOne",
      //此项为你要显示选择后的日期的input，不填写默认为上一行的"dateShowBtn"
      beginYear: "",
      //此项为Mdate的初始年份，不填写默认为2000
      beginMonth: "1",
      //此项为Mdate的初始月份，不填写默认为1
      endYear: "",
      //此项为Mdate的结束年份，不填写默认为当年
      endMonth: "",
      //此项为Mdate的结束月份，不填写默认为当月
      format: "YMD"
      //此项为Mdate需要显示的格式，可填写"/"或"-"或".",不填写默认为年月日
    });

    $(document).on("click", '#dateSure', function(){
       year = $('#dateSelectorOne').attr('data-year');
       month = Appendzero($('#dateSelectorOne').attr('data-month'));
      offset = 0; //页码
      limit = 10;  //每页数据固定条数
      $('.forlist li').remove();
      upCallback();
    });

    var mescroll = new MeScroll("mescroll", {
      up: {
        callback: upCallback //上拉加载的回调
        ,
        empty: {
          //列表第一页无任何数据时,显示的空提示布局; 需配置warpId或clearEmptyId才生效;
          warpId:'mescroll', //父布局的id; 如果此项有值,将不使用clearEmptyId的值;
          icon: null, //图标,默认null
          tip: "暂无新的数据~", //提示
          btntext: "", //按钮,默认""
          btnClick: null, //点击按钮的回调,默认null
        },
      }
    });
    function Appendzero (obj) {
      if (obj < 10) return "0" + obj; else return obj;
    }
    //上拉加载的回调 page = {num:1, size:5}; num:当前页 默认从1开始, size:每页数据条数,默认5
    function upCallback(page) {
      $.ajax({
        url: '/admin/agent/info/mobileBill/agentid/'+agentid+'&offset='+offset+'&limit='+limit+"&date="+year+month,
        dataType:'json',
        type:'GET',
        success: function(json) {
          offset += limit++;
          limit = 10;
          $('.forlist').append(render(json));
          mescroll.endByPage(json.rows.length, json.total);
        },
        error: function(e) {
          //联网失败的回调,隐藏下拉刷新和上拉加载的状态
          mescroll.endErr();
        }
      });
    }

    function render(data)
    {
      $('.zhichu').html(data.spending);
      $('.shouru').html(data.income);
      var html = '';
      $.each(data.rows,function (index,value) {
        if(value.type == 2)
        {
          html +='<li>\n' +
            '            <img src="/agent/img/zhichu.jpg"/>\n' +
            '            <div>\n' +
            '                <p>'+value.note+'</p>\n' +
            '                <p>'+value.createtime_text+'</p>\n' +
            '            </div>\n' +
            '            <span>-'+value.amount+'</span>\n' +
            '        </li>';
        }
        if(value.type != 2)
        {
          {
            html +='<li>\n' +
              '            <img src="/agent/img/agent.jpg"/>\n' +
              '            <div>\n' +
              '                <p>'+value.note+'</p>\n' +
              '                <p>'+value.createtime_text+'</p>\n' +
              '            </div>\n' +
              '            <span style="color: #f3494c;">+'+value.amount+'</span>\n' +
              '        </li>';
          }
        }
      });
      return html;
    }
  });
  $(function(){
    var myHeight = $(window).height();
    var topHeight = $('.top').height();
    var blankHeight = $('.blank').height();
    var dateHeight = $('.date').height()+parseInt($('.date').css('padding-top'))+parseInt($('.date').css('padding-bottom'));
    var footerHeight = $('.footer').height()+parseInt($('.footer').css('padding-top'))+parseInt($('.footer').css('padding-bottom'));
    $(".mescroll").css('height',myHeight-topHeight-blankHeight-dateHeight-footerHeight);
  });

</script>
<script>
  var agentid = {$agent.id};
  //	添加保证金
  var myHeight = $(window).height();
  $(".deposit_mask").css('height',myHeight);
  $('.add_deposit').click(function(){
    $('.deposit_mask').show();
  });
  $('.deposit_close').click(function(){
    $('.deposit_mask').hide();
  });
  function goods_cut($val){
    var num_val=document.getElementById('sku_number');
    var new_num=num_val.value;
    var Num = parseInt(new_num);
    if(Num>1)Num=Num-1;
    num_val.value=Num;
  }
  function goods_add($val){
    var num_val=document.getElementById('sku_number');
    var new_num=num_val.value;
    var Num = parseInt(new_num);
    Num=Num+1;
    num_val.value=Num;
  }
  //添加保证金
  $('.submit_deposit').click(function(){
    var amount = $('#sku_number').val();
    var content = $('#content').val();
    if(content.length == 0)
    {
        alert('请填写备注');
        return false;
    }
    $.ajax({
      url: '/admin/agent/info/mobileAddMargin/agentid/'+agentid,
      dataType:'json',
      type:'post',
      data:{amount:amount,content:content},
      success: function(json) {
        alert(json.msg);
        if(json.status == 0)
        {
          window.location.reload();
        }
      }
    });
    $('.deposit_mask').hide();
  });
  //  抵扣费用调整
  $(".deduct_mask").css('height',myHeight);
  $('.add_deduct').click(function(){
    $('.deduct_mask').show();
    $('.baozheng').text($('.money_left p:last-child').html());
  });
  $('.deduct_close').click(function(){
    $('.deduct_mask').hide();
  });
  $('.submit_deduct').click(function(){
    $.ajax({
      url: '/admin/agent/info/mobileUpMargin/agentid/'+agentid,
      dataType:'json',
      type:'post',
      data:{amount:$('.adjust').val()},
      success: function(json) {
        alert(json.msg);
        if(json.status == 0)
        {
          window.location.reload();
        }
      }
    });
    $('.deduct_mask').hide();
    // $('.money_right p:last-child').text('￥'+$('.adjust').val()+'.00');
  });

</script>
</html>
